function race(arr) {
    
    return new Promise((resolve, reject) => {
        for(let i = 0; i < arr.length; i++) {
            Promise.resolve(arr[i]).then(res => {
                resolve(res)
            },err =>{
                reject(err)
            })
            break
        }
    })
}

let a = new Promise((resolve, reject) => {
    setTimeout(resolve('a'), 1000)
})
let b = new Promise((resolve, reject) => {
    setTimeout(resolve('b'), 500)
})
let c = new Promise((resolve, reject) => {
    setTimeout(resolve('c'), 100)
})

let test1 = race([c,a,b])
test1.then(res => console.log(res)).catch(err => console.log(err))



// let test = Promise.race([c, a, c])
// test.then(res => console.log(res), err => {
//     console.log(err);
// })
// console.log(test);